#WebAPI
#coding:utf-8
from __future__ import unicode_literals
import functools
import flask,json
import resolve
app = flask.Flask(__name__)
def Allow_Cross_Domain(fun):
    @functools.wraps(fun)
    def wrapper_fun(*args, **kwargs):
        rst = flask.make_response(fun(*args, **kwargs))
        rst.headers['Access-Control-Allow-Origin'] = '*'
        rst.headers['Access-Control-Allow-Methods'] = 'PUT,GET,POST,DELETE'
        allow_headers = "Referer,Accept,Origin,User-Agent"
        rst.headers['Access-Control-Allow-Headers'] = allow_headers
        return rst
    return wrapper_fun

@app.route('/rejson')
@app.route('/rejson/<Next>')
@app.route('/rejson/<Next>/<Flags>')
@Allow_Cross_Domain
def index(Next="",Flags=""):
    obj = resolve.Script("C:\\Users\\bakabie\\Desktop\\TEMP\\nscript\\b.txt")
    #Flags = flask.request.form["flags"]

    #a={'%a':1,"cs":"CA_3"}
    if Flags != "":
        parm = json.loads(Flags.encode("utf-8"))
    else:
        parm = dict()
    parm["cs"] = Next.encode("utf-8")
    print parm
    return obj.Return_(parm).encode("utf-8")

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=5000,threaded=True)

